<template>
  <!-- 标准方案 -->
  <el-dialog v-model="dialogTableVisible5" :show-close="true" width="60%">
    <div style="height: 465px; overflow: hidden">
      <div style="position: absolute; top: 5px">
        <!-- inputK3Bm -->
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputAsfabh"
          placeholder="方案编号"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputAscpyt"
          placeholder="产品用途"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>

        <el-button
          style="margin-left: 0px"
          @click="searbzfa"
          v-if="searbzfaPermissions8"
          type="primary"
          >查询</el-button
        >
      </div>
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData5"
          @row-click="RowClick5"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="420px"
          height="420px"
        >
          <el-table-column fixed type="index" width="60" align="center" />
          <el-table-column fixed prop="id" label="id" width="60" align="center" />
          <el-table-column prop="fabh" label="方案编号" width="120" align="center" />
          <el-table-column prop="famc" label="方案名称" width="120" align="center" />
          <el-table-column prop="djrq" label="单据日期" width="90" align="center" />
          <el-table-column prop="djzt" label="单据状态" width="80" align="center" />
          <el-table-column prop="cslx" label="测算类型" width="100" align="center" />
          <el-table-column prop="cpyt" label="产品用途" width="80" align="center" />
          <el-table-column prop="kh" label="客户" width="120" align="center" />
          <el-table-column prop="cz" label="材质" width="120" align="center" />
          <el-table-column prop="hd" label="厚度" width="120" align="center" />
          <el-table-column prop="kd" label="宽度" width="120" align="center" />
          <el-table-column prop="csfs" label="测算方式" width="80" align="center" />
          <el-table-column prop="dwjs" label="单位基数" width="80" align="center" />
          <el-table-column prop="ywy" label="业务员" width="80" align="center" />
          <el-table-column prop="ywygh" label="业务员工号" width="180" />
          <el-table-column prop="bmgh" label="部门工号" align="center" />
          <el-table-column prop="zdr" label="制单人" align="center" />
          <el-table-column prop="zdbm" label="制单部门" align="center" />
          <el-table-column prop="zdsj" label="制单时间" width="200" align="center" />
          <el-table-column
            fixed="right"
            width="280"
            align="center"
            prop="bz"
            label="备注"
          />
        </el-table>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page5"
            v-model:page-size="limit5"
            :page-sizes="[10, 20, 30, 40]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total5"
            @size-change="handleSizeChange5"
            @current-change="handleCurrentChange5"
          />
        </div>
      </div>
    </div>
  </el-dialog>
  <!-- v-model="MaterialsFixed_window_Purposes" -->
  <el-dialog v-model="dialogTableVisible4" :show-close="true" width="60%">
    <div style="height: 465px; overflow: hidden">
      <div style="position: absolute; top: 5px">
        <!-- inputK3Bm -->
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputytbm"
          placeholder="编码"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputytfl"
          placeholder="分类"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputytdy"
          placeholder="用途"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-button style="margin-left: 0px" @click="searcpyt" type="primary"
          >查询</el-button
        >
      </div>
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData4"
          @row-click="RowClick4"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="420px"
          height="420px"
        >
          <el-table-column prop="ytbm" label="编码" width="60" align="center" />
          <el-table-column prop="ytfl" label="分类" />
          <el-table-column prop="ytmc" label="用途" width="180" />
          <el-table-column prop="remark" label="备注" />
        </el-table>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page4"
            v-model:page-size="limit4"
            :page-sizes="[10, 20, 30, 40]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total4"
            @size-change="handleSizeChange4"
            @current-change="handleCurrentChange4"
          />
        </div>
      </div>
    </div>
  </el-dialog>

  <el-dialog v-model="dialogTableVisible3" :show-close="true" width="60%">
    <div style="height: 465px; overflow: hidden">
      <div style="position: absolute; top: 5px">
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputYwybh"
          placeholder="业务员编号"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputYwymc"
          placeholder="业务员名称"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>

        <el-button
          style="margin-left: 0px"
          @click="searchYwy"
          v-if="searchYwyPermissions8"
          type="primary"
          >查询</el-button
        >
        <el-button
          style="margin-left: 2px"
          @click="updatYwy"
          v-if="updatYwyPermissions8"
          type="success"
          >更新业务员</el-button
        >
      </div>
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData3"
          @row-click="RowClick3"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="420px"
          height="420px"
        >
          <el-table-column prop="userId" label="Id" width="60" align="center" />
          <el-table-column prop="name" label="业务员" />
          <el-table-column prop="username" label="业务员编号" width="180" />
          <el-table-column prop="bmmc" label="部门名称" />
          <el-table-column prop="departmentId" label="部门编号" />
          <el-table-column prop="sszz" label="所属组织" />
        </el-table>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page3"
            v-model:page-size="limit3"
            :page-sizes="[100, 200, 300, 400]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total3"
            @size-change="handleSizeChange3"
            @current-change="handleCurrentChange3"
          />
        </div>
      </div>
    </div>
  </el-dialog>

  <el-dialog v-model="dialogTableVisible1" :show-close="false" align-center width="60%">
    <div style="height: 465px; overflow: hidden">
      <div style="position: absolute; top: 5px">
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputKhBm"
          placeholder="客户编码"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-input
          style="width: 30%; margin-left: 2px"
          v-model="inputKhMc"
          placeholder="客户名称"
        >
          <template #prefix>
            <el-icon class=""><search /></el-icon>
          </template>
        </el-input>
        <el-button style="margin-left: 5px" @click="searchKh" type="primary"
          >查询</el-button
        >
      </div>
      <div class="dialogDiv">
        <el-table
          border
          stripe
          :data="tableData1"
          style="width: 100%"
          @row-click="RowClick1"
          :cell-style="cellStyle"
          :header-cell-style="headerCellStyle"
          max-height="420px"
          height="420px"
        >
          <el-table-column prop="id" label="Id" width="180" />
          <el-table-column prop="khbm" label="客户编码" width="180" />
          <el-table-column prop="khmc" label="客户名称" />
        </el-table>
        <div class="demo-pagination-block">
          <el-pagination
            v-model:current-page="page1"
            v-model:page-size="limit1"
            :page-sizes="[100, 200, 300, 400]"
            :small="small"
            :disabled="disabled"
            :background="background"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total1"
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
          />
        </div>
      </div>
    </div>
  </el-dialog>
  <!-- 添加 -->
  <div
    v-if="dialogTableVisible"
    :fullscreen="false"
    :modal="false"
    :show-close="false"
    :width="screenWidth + 20 + 'px'"
    :append-to-body="true"
    style="
      position: absolute;
      left: 6rem;
      margin-top: 42px;
      z-index: 10;
      background-color: white;
    "
    :close-on-click-modal="false"
  >
    <div :style="{ width: screenWidth + 'px' }">
      <div
        :style="{
          height: '40px',
          borderBottom: '1px solid #ccc',
          width: '100%',
        }"
      >
        <div style="position: absolute; right: 15px">
          <!-- <el-button v-if="Permission" @click="upButton" type="primary">
            修改业务员</el-button
          > -->
          <el-button @click="addRow" v-if="addRowPermissions8" type="primary"
            >增行</el-button
          >
          <el-button
            @click="getDeleteRowData"
            v-if="getDeleteRowDataPermissions8"
            type="danger"
            >删除</el-button
          >
          <el-button
            type="primary"
            @click="insertMaterialsFixed"
            v-if="showInsertButton && insertMaterialsFixedPermissions8"
            >保存</el-button
          >
          <el-button
            type="primary"
            @click="updateMaterialsFixed"
            v-if="!showInsertButton && updateMaterialsFixedPermissions8"
            >保存</el-button
          >
          <el-button
            @click="OFFdialogTableVisible"
            v-if="OFFdialogTableVisiblePermissions8"
            type="danger"
            >关闭</el-button
          >
        </div>
      </div>
      <!-- <div class="vertical-line2"></div>
    <div class="vertical-line4"></div> -->
      <!-- title -->
      <div
        ref="titleDiv"
        :style="{
          backgroundColor: 'rgba(247, 247, 247, 0.903)',
          height: inputHeight + 'px',
          width: screenWidth + 'px',
        }"
      >
        <el-form :model="form" class="demo-form-inline" :inline="true">
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">需求编号</label>
            <el-input
              style="width: 180px"
              v-model="form.fabh"
              placeholder="系统自动生成"
              :readonly="true"
              disabled
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">
              <span style="color: red">*</span>单据日期</label
            >
            <el-config-provider :locale="locale">
              <el-date-picker
                style="width: 180px"
                v-model="form.djrq"
                type="date"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                placeholder="单据日期"
              />
            </el-config-provider>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                <span style="color: red">*</span>方案</label
              >
              <el-input
                style="width: 180px"
                v-model="form.bzfa"
                placeholder="请选择标准方案"
                :readonly="true"
                clearable
                @click="windowBzfa"
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">
                <span style="color: red">*</span>业务员</label
              >
              <el-input
                style="width: 180px"
                v-model="form.ywy"
                placeholder="业务员"
                :readonly="true"
                clearable
                @click="upButton"
                :disabled="isDdslDisabledYwy"
              />
            </el-form-item>

            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                >业务员部门</label
              >
              <el-input
                style="width: 180px"
                v-model="form.ywbm"
                placeholder="业务员部门"
                disabled
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px">
                标准方案编号</label
              >
              <el-input
                style="width: 180px"
                v-model="form.bzfabh"
                placeholder="标准方案编号"
                :readonly="true"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0; display: none">
              <label class="lab" style="width: 100px; padding-right: 5px">
                标准方案编号</label
              >
              <el-input
                style="width: 180px"
                v-model="form.bzfamc"
                placeholder="标准方案名称"
                :readonly="true"
                clearable
              />
            </el-form-item>
          </el-form-item>

          <el-form :model="form" class="demo-form-inline" :inline="true">
            <!-- <el-form-item class="labs" style="margin-right: 0; height: 3.8vh">
              <label class="lab" style="width: 120px">测算维度:</label>
            </el-form-item> -->
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">产品用途</label>
              <el-input
                style="width: 180px"
                v-model="form.cpyt"
                placeholder="产品用途"
                disabled
                :readonly="true"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">客户</label>
              <el-input
                style="width: 180px"
                v-model="form.kh"
                placeholder="客户"
                disabled
                :readonly="true"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">材质</label>
              <el-input
                style="width: 180px"
                v-model="form.cz"
                placeholder="材质"
                disabled
                :readonly="true"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">厚度</label>
              <el-input
                style="width: 180px"
                v-model="form.hd"
                placeholder="厚度"
                disabled
                :readonly="true"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">宽度</label>
              <el-input
                style="width: 180px"
                v-model="form.kd"
                :readonly="true"
                disabled
                placeholder="宽度"
                clearable
              />
            </el-form-item>
          </el-form>
          <el-form :model="form" class="demo-form-inline" :inline="true">
            <el-form-item class="lab" style="margin-right: 0; height: 3.8vh">
              <label class="lab" style="width: 100px; padding-right: 5px">测算类型</label>
              <el-checkbox-group v-model="checkList" class="custom-checkbox-group">
                <el-checkbox
                  style="width: 120px"
                  label="年度测算"
                  @change="handleCheckboxChange('年度测算')"
                  :disabled="true"
                />
                <el-checkbox
                  style="width: 120px"
                  label="月度测算"
                  @change="handleCheckboxChange('月度测算')"
                  :disabled="true"
                />
                <el-checkbox
                  style="width: 120px"
                  label="排产测算"
                  @change="handleCheckboxChange('排产测算')"
                  :disabled="true"
                />
                <el-checkbox
                  style="width: 120px"
                  label="算料测算"
                  @change="handleCheckboxChange('算料测算')"
                  :disabled="true"
                />
                <el-checkbox
                  :disabled="true"
                  style="width: 120px"
                  label="工序测算"
                  @change="handleCheckboxChange('工序测算')"
                />
              </el-checkbox-group>
            </el-form-item>
          </el-form>
          <el-form :model="form" class="demo-form-inline" :inline="true">
            <el-form-item class="labs" style="margin-right: 0; height: 3.8vh">
              <label class="lab" style="width: 100px; padding-right: 5px">测算方式</label>
            </el-form-item>
            <el-form-item class="lab" style="margin-right: 0; height: 3.8vh">
              <el-checkbox-group v-model="checkList1">
                <el-checkbox
                  style="width: 120px"
                  label="重量"
                  :disabled="true"
                  @change="handleCheckboxChange1('重量')"
                />
                <el-checkbox
                  style="width: 120px"
                  label="成品卷"
                  :disabled="true"
                  @change="handleCheckboxChange1('成品卷')"
                />
                <el-checkbox
                  style="width: 120px"
                  label="成品拖"
                  :disabled="true"
                  @change="handleCheckboxChange1('成品拖')"
                />
              </el-checkbox-group>
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label
                class="lab"
                style="
                  width: 48px;
                  background-color: rgba(247, 247, 247, 0.903);
                  height: 30px;
                "
              ></label>
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px">单位基数</label>
              <el-input
                style="width: 180px"
                v-model="form.dwjs"
                :disabled="true"
                placeholder="单位基数"
                clearable
              />
            </el-form-item>
            <el-form-item class="labs" style="margin-right: 0">
              <label class="lab" style="width: 100px; padding-right: 5px"
                ><span style="color: red">*</span>订单数量</label
              >
              <el-input
                ref="ddslinput"
                style="width: 180px"
                v-model="form.ddsl"
                :disabled="isDdslDisabled"
                placeholder="订单数量"
                @clear="handleChangeDwjs()"
                @change="handleChangeDwjs()"
                clearable
              />
            </el-form-item>
          </el-form>
        </el-form>
      </div>
      <!-- 子表添加 -->
      <el-form :inline="true" :model="formInline">
        <div
          :style="{
            width: screenWidth + 'px',
            'max-height': tableHeight + 'px',
            'overflow-y': 'auto',
            'overflow-x': 'hidden',
            'scrollbar-width': 'thin',
          }"
        >
          <table>
            <tr class="sticky-header" style="z-index: 99">
              <th style="width: 50px" class="table-header">序号</th>
              <th style="width: 50px" class="table-header">
                <el-checkbox @change="toggleSelectAll" v-model="selectAll"></el-checkbox>
              </th>
              <th style="width: 150px" class="table-header">物料编码</th>
              <th style="width: 150px" class="table-header">物料名称</th>
              <th style="width: 80px" class="table-header">物料规格</th>
              <th style="width: 80px" class="table-header">计量单位</th>
              <th style="width: 120px" class="table-header">标准数量</th>
              <th style="width: 120px" class="table-header">标准单价</th>
              <th style="width: 120px" class="table-header red-asterisk">订单数量</th>
              <th style="width: 120px" class="table-header">总数</th>
              <th style="width: 120px" class="table-header">金额</th>
              <th hidden style="width: 120px" class="table-header">标准金额</th>
              <th style="width: 300px" class="table-header">备注</th>
              <th style="width: 80px" class="table-header">测算方式</th>
              <th style="width: 80px" class="table-header">单位基数</th>
              <th style="width: 80px" class="table-header">操作</th>
            </tr>
            <tr v-for="(formData, index) in formDataList" :key="index">
              <td style="text-align: center">{{ index + 1 }}</td>
              <td style="text-align: center">
                <el-checkbox v-model="formData.selected"></el-checkbox>
              </td>
              <!-- 替换这些 el-input 元素 -->
              <!-- <td
              class="table-value"
              style="width: 100px; text-align: center"
              @click="openWlbm(index)"
            >
              <div>{{ formData.wlbm }}</div>
            </td> -->
              <!-- 物料编码状态 -->
              <td class="table-value" style="width: 100px; text-align: center">
                <el-input
                  v-model="formData.wlbm"
                  :disabled="true"
                  :readonly="true"
                  placeholder=""
                  clearable
                  @click="openWlbm(index)"
                />
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.wlmc }}</div>
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.wlgg }}</div>
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.jldw }}</div>
              </td>
              <td>
                <el-input
                  @clear="handleChange('bzsl', index)"
                  @change="handleChange('bzsl', index)"
                  v-model="formData.bzsl"
                  :disabled="true"
                  placeholder=""
                  clearable
                  :precision="4"
                >
                </el-input>
              </td>
              <td>
                <el-input
                  @clear="handleChange('bzdj', index)"
                  @change="handleChange('bzdj', index)"
                  v-model="formData.bzdj"
                  :disabled="true"
                  placeholder=""
                  clearable
                  :precision="4"
                >
                </el-input>
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <!-- <div>{{ formData.ddsl }}</div> -->
                <el-input
                  v-model="formData.ddsl"
                  :readonly="true"
                  placeholder=""
                  clearable
                />
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.zs }}</div>
              </td>
              <td class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.je }}</div>
              </td>
              <td hidden class="table-value" style="width: 100px; text-align: center">
                <div>{{ formData.bzje }}</div>
              </td>
              <td><el-input v-model="formData.bz" placeholder="" clearable /></td>
              <td class="table-value" style="width: 80px; text-align: center">
                <div>{{ formData.csfs }}</div>
              </td>
              <td class="table-value" style="width: 80px; text-align: center">
                <div>{{ formData.dwjs }}</div>
              </td>
              <td>
                <el-button
                  style="height: 30px; margin-top: 1px"
                  type="danger"
                  @click="handleDeletes(index)"
                  >删除</el-button
                >
              </td>
            </tr>
            <!-- 合计行 -->
            <tr
              style="
                text-align: center;
                position: sticky;
                bottom: -1px;
                background-color: #ddd;
                z-index: 99;
              "
            >
              <!-- <td colspan="9">合计：</td> -->
              <td>合计:</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td>{{ calculateTotal("bzsl") }}</td>
              <td>{{ calculateTotal("bzdj") }}</td>
              <td>{{ calculateTotal("ddsl") }}</td>
              <td>{{ calculateTotal("zs") }}</td>
              <td>{{ calculateTotal("je") }}</td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </table>
        </div>
      </el-form>
      <div style="background-color: rgba(247, 247, 247, 0.903)">
        <el-form
          :model="form"
          class="demo-form-inline"
          :inline="true"
          :style="{
            backgroundColor: ' rgba(247, 247, 247, 0.903)',
            width: screenWidth - 10 + 'px',
            height: '120px',
          }"
        >
          <el-form-item class="lab" style="margin-right: 0">
            <el-input
              :style="{
                width: '180vh',
                zIndex: '99',
                backgroundColor: '#ffffff',
                resize: 'none',
                height: '50px',
              }"
              type="textarea"
              v-model="form.bz"
              placeholder="备注"
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">制单人</label>
            <el-input
              v-model="form.zdr"
              style="width: 200px; height: 3.5vh"
              disabled
              placeholder="制单人"
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">制单时间</label>
            <el-config-provider :locale="locale">
              <el-date-picker
                style="width: 200px"
                disabled
                v-model="form.zdsj"
                type="datetime"
                placeholder="制单时间"
              />
            </el-config-provider>
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">修改人</label>
            <el-input
              style="width: 180px"
              v-model="form.xgr"
              disabled
              placeholder="修改人"
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">修改时间</label>
            <el-config-provider :locale="locale">
              <el-date-picker
                style="width: 200px"
                disabled
                v-model="form.xgsj"
                type="datetime"
                placeholder="修改时间"
              />
            </el-config-provider>
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0">
            <label class="lab" style="width: 100px; padding-right: 5px">审核人</label>
            <el-input
              style="width: 200px"
              v-model="form.shr"
              disabled
              placeholder="审核人"
              clearable
            />
          </el-form-item>
          <el-form-item class="labs" style="margin-right: 0; heiht: 3.5vh">
            <label class="lab" style="width: 100px; padding-right: 5px">审核时间:</label>
            <el-config-provider :locale="locale">
              <el-date-picker
                style="width: 200px"
                disabled
                v-model="form.shsj"
                type="datetime"
                placeholder="审核时间"
              />
            </el-config-provider>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
  <!-- 页面布局 -->
  <div>
    <el-container>
      <el-header height="65px" :style="{ 'border-bottom': '1px solid #ccc' }">
        <!-- 头部按钮 -->
        <el-row type="flex" justify="end" style="background-color: rgb(211, 227, 253)">
          <div>
            <el-button
              @click="searchButton"
              v-if="searchButtonPermissions8"
              type="primary"
            >
              查询</el-button
            >
            <el-button
              @click="handleAction1"
              v-if="handleAction1Permissions8"
              type="success"
              >新增</el-button
            >
            <el-button
              @click="handleWarning0"
              v-if="handleWarning0Permissions8"
              type="warning"
              >审核</el-button
            >
            <el-button
              @click="handleWarning1"
              v-if="handleWarning1Permissions8"
              type="danger"
              >弃审</el-button
            >
            <el-button @click="handleDelete" v-if="handleDeletePermissions8" type="danger"
              >删除</el-button
            >
            <!-- <el-button style="height: 4vh" @click="handleAction2" type="success"
              >增加定义</el-button
            > -->
          </div>
          <!-- <div class="title">包材需求计算</div> -->
        </el-row>
        <div
          style="margin-left:6rem;height: 30px;width=100%; background:rgb(241,244,243);margin-bottom: 0;position: relative; display: flex; justify-content: flex-start;"
        >
          <el-input
            style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
            v-model="MaterialsFixed_fabh"
            placeholder="方案编号"
          >
            <template #prefix>
              <el-icon class=""><search /></el-icon>
            </template>
          </el-input>
          <el-input
            style="width: 10%; height: 25px; margin-left: 2px; margin-top: 2px"
            v-model="MaterialsFixed_cpyt"
            placeholder="产品用途"
          >
            <template #prefix>
              <el-icon class=""><search /></el-icon>
            </template>
          </el-input>
        </div>
      </el-header>
      <el-container>
        <el-container>
          <el-main style="padding: 2px 2px 0 2px; margin-left: 6rem">
            <el-table
              v-loading="loading"
              ref="table"
              :data="tableData"
              border
              stripe
              :cell-style="cellStyle"
              :header-cell-style="headerCellStyle"
              @selection-change="handleSelectionChange"
              @row-dblclick="handleRowClick"
              @row-click="RowClick"
              :row-style="rowState"
              :row-key="(row) => row.id"
              :max-height="screenHeight"
              :height="screenHeight"
              :summary-method="getSummaries"
              empty-text="无数据"
              show-summary
            >
              <el-table-column fixed type="index" width="60" align="center" />
              <el-table-column fixed type="selection" width="50" align="center" />
              <el-table-column fixed prop="id" label="id" width="60" align="center" />
              <el-table-column prop="fabh" label="需求编号" width="120" align="center" />
              <el-table-column
                prop="bzfabh"
                label="方案编号"
                width="120"
                align="center"
              />
              <el-table-column
                prop="bzfamc"
                label="方案名称"
                width="120"
                align="center"
              />
              <el-table-column prop="djrq" label="单据日期" width="90" align="center" />
              <el-table-column prop="djzt" label="单据状态" width="80" align="center" />
              <el-table-column prop="cslx" label="测算类型" width="100" align="center" />
              <el-table-column prop="cpyt" label="产品用途" width="80" align="center" />
              <el-table-column prop="kh" label="客户" width="120" align="center" />
              <el-table-column prop="cz" label="材质" width="120" align="center" />
              <el-table-column prop="hd" label="厚度" width="120" align="center" />
              <el-table-column prop="kd" label="宽度" width="120" align="center" />
              <el-table-column prop="csfs" label="测算方式" width="80" align="center" />
              <el-table-column prop="dwjs" label="单位基数" width="80" align="center" />
              <el-table-column prop="ddsl" label="订单数量" width="80" align="center" />
              <el-table-column prop="ywy" label="业务员" width="80" align="center" />
              <el-table-column
                prop="ywygh"
                label="业务员工号"
                width="80"
                align="center"
              />
              <el-table-column prop="ywbm" label="业务部门" width="80" align="center" />
              <el-table-column prop="ywbmgh" label="部门工号" width="80" align="center" />
              <el-table-column prop="zdr" label="制单人" width="80" align="center" />
              <el-table-column prop="zdbm" label="制单部门" width="80" align="center" />
              <el-table-column prop="zdsj" label="制单时间" width="140" align="center" />
              <el-table-column prop="shr" label="审核人" width="80" align="center" />
              <el-table-column prop="shbm" label="审核部门" width="120" align="center" />
              <el-table-column prop="shsj" label="审核时间" width="140" align="center" />
              <el-table-column prop="xgr" label="修改人" width="80" align="center" />
              <el-table-column prop="xgbm" label="修改部门" width="80" align="center" />
              <el-table-column prop="xgsj" label="修改时间" width="140" align="center" />

              <el-table-column
                fixed="right"
                prop="bz"
                label="备注"
                width="280"
                align="center"
              />
            </el-table>
            <div class="demo-pagination-block" style="">
              <el-pagination
                v-model:current-page="page"
                v-model:page-size="limit"
                :page-sizes="[50, 500, 1000, 1500, 2000, 8000]"
                :small="true"
                :background="true"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </el-main>

          <!-- <el-footer style="background: linear-gradient(to right, #f9f9fc, #fef5f0)"
            >Footer</el-footer
          > -->
        </el-container>
        <!-- <el-aside width="20%"></el-aside> -->
      </el-container>
    </el-container>
  </div>
</template>
<script setup lang="ts">
import {
  ref,
  watch,
  reactive,
  onMounted,
  onBeforeMount,
  computed,
  nextTick,
  onUnmounted,
  toRefs,
} from "vue";
import { Delete, Edit, Search, Share, Upload, Calendar } from "@element-plus/icons-vue";
import {
  ElTable,
  TableColumnCtx,
  ElButton,
  ElDialog,
  dialogEmits,
  ElMessage,
  FormRules,
  FormInstance,
} from "element-plus";
import { CircleCloseFilled } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import axios from "../axios/axiosInstance";
import Cookies from "js-cookie";
import { format } from "date-fns";

// 日期中文
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
const Permission = ref(false);
const isDdslDisabledYwy = ref(true);
const router = useRouter();
const isDdslDisabled = ref(true);
// 权限控制
const searbzfaPermissions8 = ref(false);
const searchYwyPermissions8 = ref(false);
const updatYwyPermissions8 = ref(false);
const addRowPermissions8 = ref(false);
const getDeleteRowDataPermissions8 = ref(false);
const insertMaterialsFixedPermissions8 = ref(false);
const updateMaterialsFixedPermissions8 = ref(false);
const OFFdialogTableVisiblePermissions8 = ref(false);
const searchButtonPermissions8 = ref(false);
const handleAction1Permissions8 = ref(false);
const handleWarning0Permissions8 = ref(false);
const handleWarning1Permissions8 = ref(false);
const handleDeletePermissions8 = ref(false);
const menuId = ref(8);
const buttonVariables = {
  searbzfaPermissions8,
  searchYwyPermissions8,
  updatYwyPermissions8,
  addRowPermissions8,
  getDeleteRowDataPermissions8,
  insertMaterialsFixedPermissions8,
  updateMaterialsFixedPermissions8,
  OFFdialogTableVisiblePermissions8,
  searchButtonPermissions8,
  handleAction1Permissions8,
  handleWarning0Permissions8,
  handleWarning1Permissions8,
  handleDeletePermissions8,
};
const selectPermissionsButton = () => {
  const userName = Cookies.get("userName");

  axios({
    url: "/select/Permissions/Button",
    method: "post",
    data: {
      userName: userName,
      menuId: menuId.value,
    },
  }).then((res) => {
    res.data.forEach((button) => {
      const buttonName = button.buttonName;
      if (buttonVariables.hasOwnProperty(buttonName)) {
        buttonVariables[buttonName].value = true;
      }
    });
  });
};
selectPermissionsButton();
// 计算高度
const screenHeight = ref(null);
const dynamicHeight = ref(null);
const dynamicHeightYtfl = ref(null);
const tableHeight = ref(null);

const getScreenHeight = () => {
  console.log(window.innerHeight);
  screenHeight.value = window.innerHeight - 146 - 42 + 55;
  dynamicHeight.value = `${window.innerHeight - 55 + 55}px`;
  dynamicHeightYtfl.value = window.innerHeight - 120 + 55;
  // tableHeight.value = window.innerHeight - 435 + 19 - 42 + 55;
  tableHeight.value = window.innerHeight - 353;
  console.log("高度" + window.innerHeight);
  console.log("子表:" + tableHeight.value);
};
getScreenHeight();
const activeIndex = ref("1");
const handleSelect = (key: string, keyPath: string[]) => {};
// 主表
const dialogTableVisible = ref(false);
const dialogTableVisible1 = ref(false);
const dialogTableVisible2 = ref(false);
const dialogTableVisible3 = ref(false);
const dialogTableVisible4 = ref(false);
const dialogTableVisible5 = ref(false);
const checkList = ref([]);
const checkList1 = ref([]);
const showInsertButton = ref(true);
const screenWidth = ref(window.innerWidth);
const inputHeight = ref(200);

const handleResize = () => {
  screenWidth.value = window.innerWidth;
  screenWidth.value = screenWidth.value - 96;
  if (screenWidth.value / 280 < 5) {
    inputHeight.value = 200;
    return;
  }
  inputHeight.value = 150;
};
handleResize();
const handleRowClick = (row) => {
  isDdslDisabled.value = false;
  isDdslDisabledYwy.value = true;
  dialogTableVisible.value = true;
  showInsertButton.value = false;
  form.fabh = row.fabh;
  form.djrq = row.djrq;
  form.cpyt = row.cpyt;
  form.kh = row.kh;
  form.cz = row.cz;
  form.hd = row.hd;
  form.kd = row.kd;
  form.dwjs = row.dwjs;
  form.bz = row.bz;
  form.zdr = row.zdr;
  form.zdsj = row.zdsj;
  form.shr = row.shr;
  form.shsj = row.shsj;
  form.ddsl = row.ddsl;
  form.bzfabh = row.bzfabh;
  form.bzfamc = row.bzfamc;
  form.sszz = row.sszz;
  form.famc = row.famc;
  form.ywy = row.ywy;
  form.ywbm = row.ywbm;
  form.bzfa = "(" + row.bzfabh + ")" + row.bzfamc;
  const userName = Cookies.get("userName");
  const currentFormattedDateTime = getCurrentFormattedDateTime();
  const currentFormattedDate = getCurrentFormattedDate();
  form.xgsj = currentFormattedDateTime;
  form.xgr = userName;
  // 回显测算类型
  // checkList
  checkList.value = row.cslx.split(",");
  checkList1.value = row.csfs.split(",");
  // 回显子表
  axios({
    url: "/select/AssistList",
    method: "post",
    data: {
      id: row.id,
    },
  }).then((res) => {
    const materialList = res.data;
    if (materialList == 0) {
      for (let a = 0; a < 21; a++) {
        addRow();
      }
      return;
    }
    const formattedData = materialList.map((material, index) => ({
      ddsl: material.ddsl,
      wlbm: material.wlbm,
      wlmc: material.wlmc,
      wlgg: material.wlgg,
      jldw: material.jldw,
      bzsl: material.bzsl,
      bzdj: material.bzdj,
      bzje: material.bzje,
      csfs: material.csfs,
      dwjs: material.dwjs,
      zs: material.zs,
      je: material.je,
      selected: false,
    }));
    formDataList.value = formattedData;
    for (let a = 0; a < 21; a++) {
      addRow();
    }
  });
};
const handleCheckboxChange = (label) => {
  checkList.value = [label];
};
const handleCheckboxChange1 = (label) => {
  checkList1.value = [label];

  for (let lengthCsfs = 0; lengthCsfs < formDataList.value.length; lengthCsfs++) {
    formDataList.value[lengthCsfs].csfs = checkList1.value[0];
  }
};
const form = reactive({
  fabh: "",
  djrq: "",
  cswd: "",
  cpyt: "",
  kh: "",
  cz: "",
  hd: "",
  dwjs: "",
  bz: "",
  zdr: "",
  zdsj: "",
  xgr: "",
  xgsj: "",
  shr: "",
  shsj: "",
});
//下拉框内容
const options = [
  {
    value: "Option1",
    label: "Option1",
  },
  {
    value: "Option2",
    label: "Option2",
  },
  {
    value: "Option3",
    label: "Option3",
  },
  {
    value: "Option4",
    label: "Option4",
  },
  {
    value: "Option5",
    label: "Option5",
  },
];

// 子表
let selectedRowIndex = -1; // 初始化为-1，表示没有选中的行
let clearSelection = true;
// 方法：获取已勾选数据
const getSelectedRowsData = () => {
  const selectedData = formDataList.value.filter((formData) => formData.selected);
  // 在这里可以执行想要的操作，例如将 selectedData 发送到服务器或者在控制台中打印出来
};
//多选
const selectAll = ref(false);
const toggleSelectAll = () => {
  for (const formData of formDataList.value) {
    formData.selected = selectAll.value === true;
  }
};
// 单位基数
const handleChangeDwjs = () => {
  if (!isNaN(parseFloat(form.ddsl)) && isFinite(form.ddsl)) {
    var ddslFloat = parseFloat(form.ddsl).toFixed(4);
    form.ddsl = ddslFloat;
    for (let length = 0; length < formDataList.value.length; length++) {
      if (!formDataList.value[length].wlbm == "") {
        formDataList.value[length].ddsl = ddslFloat;
        //总数
        formDataList.value[length].zs = parseFloat(
          (formDataList.value[length].ddsl / formDataList.value[length].dwjs) *
            formDataList.value[length].bzsl
        ).toFixed(2);
        //金额
        formDataList.value[length].je = parseFloat(
          (formDataList.value[length].ddsl / formDataList.value[length].dwjs) *
            formDataList.value[length].bzsl *
            formDataList.value[length].bzdj
        ).toFixed(2);
      }
    }
    return;
  }
  form.ddsl = "";
};
// 计算金额
const handleChange = (field, index) => {
  //   formDataList.value[index].issl = true;
  let inputValue = formDataList.value[index][field];

  // formDataList.value[index].[field] = true;
  inputValue = parseFloat(inputValue).toFixed(4);

  // const inputValue = formDataList.value[index][field];
  const isValidInput = /^-?\d+(\.\d{0,4})?$/.test(inputValue);

  if (isValidInput) {
    // 如果是有效的数字，更新 formDataList
    formDataList.value[index][field] = parseFloat(inputValue);
    if (field === "bzsl") {
      formDataList.value[index].issl = true;
    }

    if (field === "bzdj") {
      formDataList.value[index].isdj = true;
    }

    // 检查是否有数字值
    const hasBzsl = typeof formDataList.value[index].bzsl === "number";
    const hasBzdj = typeof formDataList.value[index].bzdj === "number";
    // 如果 bzsl 和 bzdj 都有数字值，计算 bzje
    if (hasBzsl && hasBzdj) {
      const bzsl = formDataList.value[index].bzsl || 0;
      const bzdj = formDataList.value[index].bzdj || 0;

      // 计算标准金额，四舍五入保留两位小数
      formDataList.value[index].bzje = (bzsl * bzdj).toFixed(2);
      return;
    }
    formDataList.value[index].bzje = 0;
  } else {
    // 如果输入值不符合要求，进行相应的处理，比如清空输入框或者给出提示
    formDataList.value[index][field] = null;
    formDataList.value[index].bzje = 0;
    if (field === "bzsl") {
      formDataList.value[index].issl = false;
    }

    if (field === "bzdj") {
      formDataList.value[index].isdj = false;
    }
    console.warn(`Invalid numeric input for ${field} in row ${index}`);
  }
};

type ColumnKey =
  | "wlbm"
  | "wlmc"
  | "wlgg"
  | "jldw"
  | "bzsl"
  | "bzdj"
  | "bz"
  | "csfs"
  | "dwjs";
//合计行
const calculateTotal = (columnKey: ColumnKey) => {
  let total = 0;
  for (const formData of formDataList.value) {
    // 将字符串转换为数字，然后累加
    total += parseFloat(formData[columnKey]) || 0;
  }
  // 返回合计值
  return total.toFixed(4); // 这里假设合计值需要保留两位小数
};
//删除一行
const handleDeletes = (index: number) => {
  formDataList.value.splice(index, 1);
  if (formDataList.value.length === 0) {
    addRow();
  }
};
//删除已勾选
const getDeleteRowData = () => {
  const selectedIndexes: any = [];

  // 找到已勾选行的索引
  formDataList.value.forEach((formData, index) => {
    if (formData.selected) {
      selectedIndexes.push(index);
    }
  });

  // 删除已勾选行
  for (let i = selectedIndexes.length - 1; i >= 0; i--) {
    formDataList.value.splice(selectedIndexes[i], 1);
  }

  // 如果没有剩余行数据，添加一行
  if (formDataList.value.length === 0) {
    addRow();
  }
  selectAll.value = false;
};
const formInline = ref([]);
const formDataList = ref([
  {
    wlbm: "",
    wlmc: "",
    wlgg: "",
    jldw: "",
    bzsl: "",
    bzdj: "",
    bzje: "",
    bz: "",
    csfs: "",
    dwjs: "",
    ddsl: "",
    zs: "",
    je: "",
    selected: false,
    issl: false,
    isdj: false,
  },
]);

// 添加按钮点击时，添加一组空表单数据
const addRow = () => {
  formDataList.value.push({
    wlbm: "",
    wlmc: "",
    wlgg: "",
    jldw: "",
    bzsl: "",
    bzdj: "",
    bzje: "",
    bz: "",
    csfs: "",
    dwjs: "",
    selected: false,
  });
};
// 背景色
const verticalLine3 = ref(null);
// 分页
const page = ref(1);
const page1 = ref(1);
const page2 = ref(1);
const page3 = ref(1);
const page4 = ref(1);
const page5 = ref(1);
const limit = ref(50);
const limit1 = ref(50);
const limit2 = ref(50);
const limit3 = ref(50);
const limit4 = ref(50);
const limit5 = ref(50);
const total = ref(10);
const total1 = ref(10);
const total2 = ref(10);
const total3 = ref(10);
const total4 = ref(10);
const total5 = ref(10);
const loading = ref(false);
const selectCookies = () => {};
selectCookies();
const handleSizeChange = (val: number) => {
  loading.value = true;
  tableData.value = [];
  nextTick(() => {
    const userName = Cookies.get("userName");
    axios({
      url: "/select/Assist",
      method: "post",
      data: {
        cpyt: MaterialsFixed_cpyt.value,
        fabh: MaterialsFixed_fabh.value,
        userName: userName,
        page: page.value,
        limit: limit.value,
      },
    }).then((res) => {
      const materialList = res.data;
      if (materialList.length == 0) {
        loading.value = false;
        return;
      }
      total.value = res.data[0].total;

      tableData.value = materialList.map((material) => ({
        // 根据 djzt 的值设置状态
        djzt: material.djzt === 0 ? "待审" : "已审核",
        id: material.id,
        fabh: material.fabh,
        djrq: material.djrq,
        cslx: material.cslx,
        cpyt: material.cpyt,
        kh: material.kh,
        cz: material.cz,
        hd: material.hd,
        kd: material.kd,
        csfs: material.csfs,
        dwjs: material.dwjs,
        ywy: material.ywy,
        ywbm: material.ywbm,
        bz: material.bz,
        zdr: material.zdr,
        ddsl: material.ddsl,
        zdbm: material.zdbm,
        zdsj: material.zdsj,
        shr: material.shr,
        shbm: material.shbm,
        shsj: material.shsj,
        xgr: material.xgr,
        xgbm: material.xgbm,
        xgsj: material.xgsj,
        ywygh: material.ywygh,
        ywbmgh: material.ywbmgh,
        bzfabh: material.bzfabh,
        bzfamc: material.bzfamc,
      }));

      for (let a = 0; a < 20; a++) {
        addRow();
      }
      //制单人
      form.zdr = userName;
      // 制单时间
      const currentFormattedDateTime = getCurrentFormattedDateTime();
      const currentFormattedDate = getCurrentFormattedDate();
      form.zdsj = currentFormattedDateTime;
      form.djrq = currentFormattedDate;
      loading.value = false;
    });
  });
  loading.value = true;
};
const handleCurrentChange = (val: number) => {
  loading.value = true;
  tableData.value = [];
  nextTick(() => {
    const userName = Cookies.get("userName");
    axios({
      url: "/select/Assist",
      method: "post",
      data: {
        cpyt: MaterialsFixed_cpyt.value,
        fabh: MaterialsFixed_fabh.value,
        userName: userName,
        page: page.value,
        limit: limit.value,
      },
    }).then((res) => {
      const materialList = res.data;
      if (materialList.length == 0) {
        loading.value = false;
        return;
      }
      total.value = res.data[0].total;

      tableData.value = materialList.map((material) => ({
        // 根据 djzt 的值设置状态
        djzt: material.djzt === 0 ? "待审" : "已审核",
        id: material.id,
        fabh: material.fabh,
        djrq: material.djrq,
        cslx: material.cslx,
        cpyt: material.cpyt,
        kh: material.kh,
        cz: material.cz,
        hd: material.hd,
        kd: material.kd,
        csfs: material.csfs,
        dwjs: material.dwjs,
        ywy: material.ywy,
        ywbm: material.ywbm,
        bz: material.bz,
        zdr: material.zdr,
        ddsl: material.ddsl,
        zdbm: material.zdbm,
        zdsj: material.zdsj,
        shr: material.shr,
        shbm: material.shbm,
        shsj: material.shsj,
        xgr: material.xgr,
        xgbm: material.xgbm,
        xgsj: material.xgsj,
        ywygh: material.ywygh,
        ywbmgh: material.ywbmgh,
        bzfabh: material.bzfabh,
        bzfamc: material.bzfamc,
      }));

      for (let a = 0; a < 20; a++) {
        addRow();
      }
      //制单人
      form.zdr = userName;
      // 制单时间
      const currentFormattedDateTime = getCurrentFormattedDateTime();
      const currentFormattedDate = getCurrentFormattedDate();
      form.zdsj = currentFormattedDateTime;
      form.djrq = currentFormattedDate;
      loading.value = false;
    });
  });
  loading.value = true;
};
// 搜索框
const MaterialsFixed_fabh = ref("");
const MaterialsFixed_cpyt = ref("");
const inputMc = ref("");
const inputBm = ref("");
const inputKhBm = ref("");
const inputKhMc = ref("");
const inputK3Bm = ref("");
const inputK3Mc = ref("");
const inputywy = ref("");
const inputywygh = ref("");
const inputytbm = ref("");
const inputytfl = ref("");
const inputytdy = ref("");
const inputAsfabh = ref("");
const inputAscpyt = ref("");
const inputYwybh = ref("");
const inputYwymc = ref("");
const userName = Cookies.get("userName");

// 搜索
const searchButton = () => {
  loading.value = true;
  tableData.value = [];
  nextTick(() => {
    const userName = Cookies.get("userName");
    axios({
      url: "/select/Assist",
      method: "post",
      data: {
        cpyt: MaterialsFixed_cpyt.value,
        fabh: MaterialsFixed_fabh.value,
        userName: userName,
        page: page.value,
        limit: limit.value,
      },
    }).then((res) => {
      const materialList = res.data;
      if (materialList.length == 0) {
        loading.value = false;
        total.value = 0;
        return;
      }
      total.value = res.data[0].total;

      tableData.value = materialList.map((material) => ({
        // 根据 djzt 的值设置状态
        djzt: material.djzt === 0 ? "待审" : "已审核",
        id: material.id,
        fabh: material.fabh,
        djrq: material.djrq,
        cslx: material.cslx,
        cpyt: material.cpyt,
        kh: material.kh,
        cz: material.cz,
        hd: material.hd,
        kd: material.kd,
        csfs: material.csfs,
        dwjs: material.dwjs,
        ywy: material.ywy,
        ywbm: material.ywbm,
        bz: material.bz,
        zdr: material.zdr,
        ddsl: material.ddsl,
        zdbm: material.zdbm,
        zdsj: material.zdsj,
        shr: material.shr,
        shbm: material.shbm,
        shsj: material.shsj,
        xgr: material.xgr,
        xgbm: material.xgbm,
        xgsj: material.xgsj,
        ywygh: material.ywygh,
        ywbmgh: material.ywbmgh,
        bzfabh: material.bzfabh,
        bzfamc: material.bzfamc,
      }));

      for (let a = 0; a < 20; a++) {
        addRow();
      }
      //制单人
      form.zdr = userName;
      // 制单时间
      const currentFormattedDateTime = getCurrentFormattedDateTime();
      const currentFormattedDate = getCurrentFormattedDate();
      form.zdsj = currentFormattedDateTime;
      form.djrq = currentFormattedDate;
      loading.value = false;
    });
  });
  loading.value = true;
};
// const input1 = ref('')
// 合计行
interface SummaryMethodProps<T = Product> {
  columns: TableColumnCtx<T>[];
  data: T[];
}
const getSummaries = (param: SummaryMethodProps) => {
  const { columns, data } = param;
  const sums: string[] = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    }

    const values = data.map((item) => Number(item[column.property]));
    if (!values.every((value) => Number.isNaN(value))) {
      sums[index] = ` ${values.reduce((prev, curr) => {
        const value = Number(curr);
        if (!Number.isNaN(value)) {
          return prev + curr;
        } else {
          return prev;
        }
      }, 0)}`;
    } else {
      sums[index] = "";
    }
    sums[index] = "";
  });

  for (let hj = 0; hj < sums.length; hj++) {
    var val = sums[hj];
    // !isNaN(parseFloat(value)) && isFinite(value);
    if (!isNaN(parseFloat(val)) && isFinite(val)) {
      sums[hj] = parseFloat(sums[hj]).toFixed(2);
      continue;
    }
  }
  return sums;
};

// 弹窗
const buttonText = ref("添加用途分类");
// 添加按钮
// 制单时间
const ywy = ref("");
const zdrbm = ref("");
const ywbm = ref("");
const ywygh = ref("");
const ywbmgh = ref("");
const handleAction1 = () => {
  dialogTableVisible.value = true;
  isDdslDisabled.value = true;
  isDdslDisabledYwy.value = false;

  showInsertButton.value = true;

  const userName = Cookies.get("userName");
  form.zdr = userName;
  for (let a = 0; a < 21; a++) {
    addRow();
  }

  const currentFormattedDateTime = getCurrentFormattedDateTime();
  const currentFormattedDate = getCurrentFormattedDate();
  form.zdsj = currentFormattedDateTime;
  form.djrq = currentFormattedDate;
  Permission.value = true;

  axios({
    url: "/select/ywy",
    method: "post",
    data: {
      userName: userName,
    },
  }).then((res) => {
    ywy.value = res.data.name;
    ywygh.value = userName;
    ywbm.value = res.data.bmmc;
    ywbmgh.value = res.data.departmentId;
    zdrbm.value = res.data.bmmc;
  });
  if (userName == "0" || userName == "admin") {
    nextTick(() => {
      dialogTableVisible3.value = true;
    });
  }
};

// 关闭弹窗
const OFFdialogTableVisible = () => {
  dialogTableVisible.value = false;
  showInsertButton.value = true;

  Object.keys(form).forEach((key) => {
    form[key] = "";
  });
  (checkList.value = ""), (checkList1.value = "");
  // 删除
  formDataList.value = [];
  // location.reload();
  page1.value = 1;
  page2.value = 1;
  page3.value = 1;
  page4.value = 1;
  page5.value = 1;
  limit1.value = 50;
  limit2.value = 50;
  limit3.value = 50;
  limit4.value = 50;
  limit5.value = 50;
};
const handleAction2 = () => {};

// 进入页面
const selectpurposes = () => {
  // 查看是否登录
  const userName = Cookies.get("userName");
  if (!userName) {
    router.push("/");
    return;
  }
  axios({
    url: "/select/Assist",
    method: "post",
    data: {
      cpyt: MaterialsFixed_cpyt.value,
      fabh: MaterialsFixed_fabh.value,
      userName: userName,
      page: page.value,
      limit: limit.value,
    },
  }).then((res) => {
    const materialList = res.data;
    if (materialList.length == 0) {
      total.value = 0;
      return;
    }
    total.value = res.data[0].total;
    tableData.value = materialList.map((material) => ({
      // 根据 djzt 的值设置状态
      djzt: material.djzt === 0 ? "待审" : "已审核",
      id: material.id,
      fabh: material.fabh,
      djrq: material.djrq,
      cslx: material.cslx,
      cpyt: material.cpyt,
      kh: material.kh,
      cz: material.cz,
      hd: material.hd,
      kd: material.kd,
      csfs: material.csfs,
      dwjs: material.dwjs,
      ywy: material.ywy,
      ywbm: material.ywbm,
      bz: material.bz,
      zdr: material.zdr,
      ddsl: material.ddsl,
      zdbm: material.zdbm,
      zdsj: material.zdsj,
      shr: material.shr,
      shbm: material.shbm,
      shsj: material.shsj,
      xgr: material.xgr,
      xgbm: material.xgbm,
      xgsj: material.xgsj,
      ywygh: material.ywygh,
      ywbmgh: material.ywbmgh,
      bzfabh: material.bzfabh,
      bzfamc: material.bzfamc,
    }));

    for (let a = 0; a < 20; a++) {
      addRow();
    }
    //制单人
    form.zdr = userName;
    // 制单时间
    const currentFormattedDateTime = getCurrentFormattedDateTime();
    const currentFormattedDate = getCurrentFormattedDate();
    form.zdsj = currentFormattedDateTime;
    form.djrq = currentFormattedDate;
  });
};
// 修改业务员
const upButton = () => {
  dialogTableVisible3.value = true;
};
// 修改
const updateMaterialsFixed = () => {
  const userName = Cookies.get("userName");
  if (!userName) {
    router.push("/");
    return;
  }
  if (form.djrq == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "单据日期未填写",
      type: "error",
    });
    return;
  }
  if (form.bzfa == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "标准方案未填写",
      type: "error",
    });
    return;
  }
  if (form.ddsl == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "订单数量未填写",
      type: "error",
    });
    return;
  }
  ElMessageBox.confirm("确认修改吗？", "提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
    center: true,
  })
    .then(() => {
      const requestData = formDataList.value.map((formData) => ({
        wlbm: formData.wlbm,
        wlmc: formData.wlmc,
        wlgg: formData.wlgg,
        jldw: formData.jldw,
        bzsl: formData.bzsl,
        bzdj: formData.bzdj,
        bzje: formData.bzje,
        bz1: formData.bz,
        ddsl: formData.ddsl,
        zs: formData.zs,
        je: formData.je,
      }));
      const currentFormattedDateTime = getCurrentFormattedDateTime();
      axios({
        url: "/update/Assist",
        method: "post",
        data: {
          userName: userName,
          fabh: form.fabh,
          djrq: form.djrq,
          cpyt: form.cpyt,
          kh: form.kh,
          cz: form.cz,
          hd: form.hd,
          kd: form.kd,
          cslx: checkList.value[0],
          csfs: checkList1.value[0],
          dwjs: form.dwjs,
          ywy: ywy.value,
          ywygh: ywygh.value,
          ywbm: ywbm.value,
          ywbmgh: ywbmgh.value,
          zdr: form.zdr,
          zdsj: form.zdsj,
          zdbm: form.zdbm,
          bz: form.bz,
          ddsl: form.ddsl,
          requestData: requestData,
          bzfabh: form.bzfabh,
          bzfamc: form.bzfamc,
          xgsj: currentFormattedDateTime,
        },
      }).then((res) => {
        if (res.data.code == 200) {
          // location.reload();
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "success",
          });
          OFFdialogTableVisible();
          selectpurposes();
          return;
        }
        ElMessage({
          center: true,
          showClose: true,
          grouping: true,
          offset: window.screen.height / 9,
          message: res.data.message,
          type: "error",
        });
      });
    })
    .catch(() => {});
};
// 新增
const insertMaterialsFixed = () => {
  const userName = Cookies.get("userName");
  if (!userName) {
    router.push("/");
    return;
  }
  if (form.djrq == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "单据日期未填写",
      type: "error",
    });
    return;
  }
  if (form.bzfa == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "标准方案未填写",
      type: "error",
    });
    return;
  }
  if (form.ddsl == "") {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "订单数量未填写",
      type: "error",
    });
    return;
  }
  // 显示确认弹窗
  ElMessageBox.confirm("确认保存吗？", "提示", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
    type: "warning",
    center: true,
  }).then(() => {
    const requestData = formDataList.value.map((formData) => ({
      wlbm: formData.wlbm,
      wlmc: formData.wlmc,
      wlgg: formData.wlgg,
      jldw: formData.jldw,
      bzsl: formData.bzsl,
      bzdj: formData.bzdj,
      bzje: formData.bzje,
      bz1: formData.bz,
      ddsl: formData.ddsl,
      zs: formData.zs,
      je: formData.je,
    }));
    axios({
      url: "/add/Assist",
      method: "post",
      data: {
        userName: userName,
        fabh: form.fabh,
        djrq: form.djrq,
        cpyt: form.cpyt,
        kh: form.kh,
        cz: form.cz,
        hd: form.hd,
        kd: form.kd,
        cslx: checkList.value[0],
        csfs: checkList1.value[0],
        dwjs: form.dwjs,
        ywy: ywy.value,
        ywygh: ywygh.value,
        ywbm: ywbm.value,
        ywbmgh: ywbmgh.value,
        zdr: form.zdr,
        zdsj: form.zdsj,
        zdbm: zdrbm.value,
        bz: form.bz,
        ddsl: form.ddsl,
        bzfabh: form.bzfabh,
        bzfamc: form.bzfamc,
        requestData: requestData,
      },
    })
      .then((res) => {
        if (res.data.code == 200) {
          // location.reload();
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "success",
          });
          OFFdialogTableVisible();
          selectpurposes();
          return;
        }
        ElMessage({
          center: true,
          showClose: true,
          grouping: true,
          offset: window.screen.height / 9,
          message: res.data.message,
          type: "error",
        });
      })
      .catch(() => {});
  });
};
// 获取当前时间
const getCurrentFormattedDateTime = () => {
  const currentDateTime = new Date();

  // 格式化当前时间
  const formattedDateTime = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
  // const formattedDateTime = format(currentDateTime, "YYYY-MM-dd HH:mm:ss");

  return formattedDateTime;
};
// 获取年月日
const getCurrentFormattedDate = () => {
  const currentDateTime = new Date();

  // 格式化当前时间，只获取年月日
  const formattedDate = currentDateTime.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
  });

  return formattedDate;
};
selectpurposes();
interface Tree {
  label: string;
  children?: Tree[];
}

// 头部按钮
const selectedRows = ref([]);
const table = ref();
const rowTable = ref([]);

const handleSelectionChange = (val) => {
  selectedRows.value = val;
};

// 审核
const handleWarning0 = () => {
  if (selectedRows.value.length === 1) {
    // 在这里执行删除选中行的逻辑，可以使用 selectedRows.value[0] 获取唯一选中的一行
    ElMessageBox.confirm("确认审核吗？", "提示", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      center: true,
    })
      .then(() => {
        const userName = Cookies.get("userName");
        const currentFormattedDateTime = getCurrentFormattedDateTime();
        axios({
          url: "/up/as/auto0",
          method: "post",
          data: {
            userName: userName,
            id: selectedRows.value[0].id,
            shsj: currentFormattedDateTime,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            ElMessage({
              center: true,
              showClose: true,
              grouping: true,
              offset: window.screen.height / 9,
              message: res.data.message,
              type: "success",
            });
            selectpurposes();
            return;
          }
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "error",
          });
        });
      })
      .catch(() => {});
  } else {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "请选择一行进行审核操作",
      type: "warning",
    });
  }
};
const handleWarning1 = () => {
  if (selectedRows.value.length === 1) {
    // 在这里执行删除选中行的逻辑，可以使用 selectedRows.value[0] 获取唯一选中的一行

    ElMessageBox.confirm("确认弃审吗？", "提示", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      center: true,
    })
      .then(() => {
        const userName = Cookies.get("userName");
        const currentFormattedDateTime = getCurrentFormattedDateTime();

        axios({
          url: "/up/as/auto1",
          method: "post",
          data: {
            userName: userName,
            id: selectedRows.value[0].id,
            shsj: currentFormattedDateTime,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            // location.reload();
            ElMessage({
              center: true,
              showClose: true,
              grouping: true,
              offset: window.screen.height / 9,
              message: res.data.message,
              type: "success",
            });
            selectpurposes();
            return;
          }
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "error",
          });
        });
      })
      .catch(() => {});
  } else {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "请选择一行进行审核操作",
      type: "warning",
    });
  }
};
// 删除
const handleDelete = () => {
  if (selectedRows.value.length === 1) {
    // 在这里执行删除选中行的逻辑，可以使用 selectedRows.value[0] 获取唯一选中的一行
    ElMessageBox.confirm("确认删除吗？", "提示", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      center: true,
    })
      .then(() => {
        const userName = Cookies.get("userName");
        axios({
          url: "/delete/Assist",
          method: "post",
          data: {
            userName: userName,
            id: selectedRows.value[0].id,
          },
        }).then((res) => {
          if (res.data.code == 200) {
            ElMessage({
              center: true,
              showClose: true,
              grouping: true,
              offset: window.screen.height / 9,
              message: res.data.message,
              type: "success",
            });
            // selectpurposes();
            searchButton();
            return;
          }
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "error",
          });
        });
      })
      .catch(() => {});
  } else {
    ElMessage({
      center: true,
      showClose: true,
      grouping: true,
      offset: window.screen.height / 9,
      message: "请选择一行进行删除操作",
      type: "warning",
    });
  }
};

// Main表格
const tableData = ref([]);
const tableData1 = ref([]);

const tableData3 = ref([]);
const tableData4 = ref([]);
const tableData5 = ref([]);

// // 设置表头样式
const headerCellStyle = {
  // E9E9E7
  borderColor: "#B9C9C7",
  backgroundColor: "#F2F4FA", // 表头背景颜色
  fontWeight: "bold", // 表头文字粗细
  color: "#1F2129",
  // padding: "0 0 0 30px",
};
const rowState = (arg) => {
  return {
    height: "20px", // 设置合适的行高值
    fontSize: "12px", // 设置合适的字体大小值
    // color: "black",
  };
};
const RowClick = (row, selection) => {
  table.value.toggleRowSelection(row);
};

const cellStyle = ({ row, column, rowIndex, columnIndex }) => {
  if (selectedRows.value.find((selectedRow) => selectedRow.id === row.id)) {
    return {
      backgroundColor: "#DFF0DB !important",
      borderColor: "#B9C9C7",
      padding: "4px",
    };
  } else {
    // #E9E9E7
    // D9D9D7   C9C9C7 A9A9A7
    return { borderColor: "#B9C9C7", padding: "4px", margin: 0 };
  }
};
// 获取客户
// searchKh;
const searchKh = () => {
  axios({
    url: "/get/Kh",
    method: "post",
    data: {
      page: page1.value,
      limit: limit1.value,
      khbm: inputKhBm.value,
      khmc: inputKhMc.value,
    },
  }).then((res) => {
    tableData1.value = res.data;
    if (res.data.length == 0) {
      return;
    }
    total1.value = res.data[0].total;
  });
};
// 63.5
const maxheight = ref(59);
const titleDiv = ref(0);
const getKh1 = () => {
  axios({
    url: "/get/Kh",
    method: "post",
    data: {
      page: page1.value,
      limit: limit1.value,
    },
  }).then((res) => {
    tableData1.value = res.data;
    const elementHeight = titleDiv.value.offsetHeight;

    // 打印元素高度
    if (res.data.length == 0) {
      return;
    }
    const windowHeight = ref(window.innerHeight);
    console.log(windowHeight.value);

    if (windowHeight.value > 800) {
      maxheight.value = 71;
    }
    if (windowHeight.value > 1000) {
      maxheight.value = 74;
    }
    total1.value = res.data[0].total;
  });
};
const handleSizeChange1 = (val: number) => {
  axios({
    url: "/get/Kh",
    method: "post",
    data: {
      page: page1.value,
      limit: limit1.value,
      khbm: inputKhBm.value,
      khmc: inputKhMc.value,
    },
  }).then((res) => {
    tableData1.value = res.data;
    if (res.data.length == 0) {
      return;
    }
    total1.value = res.data[0].total;
  });
};
const handleCurrentChange1 = (val: number) => {
  axios({
    url: "/get/Kh",
    method: "post",
    data: {
      page: page1.value,
      khbm: inputKhBm.value,
      khmc: inputKhMc.value,
    },
  }).then((res) => {
    tableData1.value = res.data;
    if (res.data.length == 0) {
      return;
    }
    total1.value = res.data[0].total;
  });
};
getKh1();
const getKh = () => {
  dialogTableVisible1.value = true;
};
const RowClick1 = (row, selection) => {
  // 客户
  form.kh = row.khmc;
  dialogTableVisible1.value = false;
};

var indexK3bm = 0;
const openWlbm = (index) => {
  indexK3bm = index;
  dialogTableVisible2.value = true;
};

// 物料编码
const RowClick2 = (row, selection) => {
  for (let i = 0; i < formDataList.value.length; i++) {
    if (formDataList.value[i].wlbm === row.k3bm) {
      const duplicateRowIndex = i + 1; // 行数从1开始
      ElMessage({
        center: true,
        showClose: true,
        grouping: true,
        offset: window.screen.height / 9,
        message: `第 ${duplicateRowIndex} 行已经存在相同的物料编码:${row.k3bm}`,
        type: "error",
      });
      // ElMessage.error(`第 ${duplicateRowIndex} 行已经存在相同的物料编码:${row.k3bm}`);
      return;
    }
  }
  formDataList.value[indexK3bm].wlbm = row.k3bm;
  formDataList.value[indexK3bm].wlmc = row.bmmc;
  formDataList.value[indexK3bm].wlgg = row.wlgg;
  formDataList.value[indexK3bm].jldw = row.jldw;
  dialogTableVisible2.value = false;
};
// 修改业务员
const updatYwy = () => {
  axios({
    // url: "/get/ywy",
    url: "/insert/Jw/Ywy",
    method: "post",
    data: {
      inputYwybh: inputYwybh.value,
      inputYwymc: inputYwymc.value,
      page: page3.value,
      limit: limit3.value,
    },
  }).then((res) => {
    ElMessageBox.confirm("确认更新吗？", "提示", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      center: true,
    })
      .then(() => {
        if (res.data.code == 200) {
          ElMessage({
            center: true,
            showClose: true,
            grouping: true,
            offset: window.screen.height / 9,
            message: res.data.message,
            type: "success",
          });
          getYwy();
          return;
        }
        ElMessage({
          center: true,
          showClose: true,
          grouping: true,
          offset: window.screen.height / 9,
          message: res.data.message,
          type: "error",
        });
      })
      .catch(() => {});
  });
};
const searchYwy = () => {
  axios({
    url: "/get/Search/ywy",
    method: "post",
    data: {
      inputYwybh: inputYwybh.value,
      inputYwymc: inputYwymc.value,
      page: page3.value,
      limit: limit3.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value = 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
const getYwy = () => {
  axios({
    // url: "/get/ywy",
    url: "/get/Search/ywy",
    method: "post",
    data: {
      inputYwybh: inputYwybh.value,
      inputYwymc: inputYwymc.value,
      page: page3.value,
      limit: limit3.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value = 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
getYwy();
const handleSizeChange3 = (val: number) => {
  axios({
    url: "/get/Search/ywy",
    method: "post",
    data: {
      inputYwybh: inputYwybh.value,
      inputYwymc: inputYwymc.value,
      page: page3.value,
      limit: limit3.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value = 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};
const handleCurrentChange3 = (val: number) => {
  axios({
    url: "/get/Search/ywy",
    method: "post",
    data: {
      inputYwybh: inputYwybh.value,
      inputYwymc: inputYwymc.value,
      page: page3.value,
      limit: limit3.value,
    },
  }).then((res) => {
    tableData3.value = res.data;
    if (res.data.length == 0) {
      total3.value = 0;
      return;
    }
    total3.value = res.data[0].total;
  });
};

const RowClick3 = (row) => {
  ywy.value = row.name;
  ywbm.value = row.username;
  ywygh.value = row.Id;
  ywbmgh.value = row.departmentId;
  form.ywy = row.name;
  form.ywbm = row.bmmc;
  form.sszz = row.sszz;
  dialogTableVisible3.value = false;
  dialogTableVisible5.value = true;
};
// 产品用途
const searcpyt = () => {
  axios({
    url: "/Material/Select/UseDefinition",
    method: "post",
    data: {
      ytbm: inputytbm.value,
      ytfl: inputytfl.value,
      ytmc: inputytdy.value,
      page: page4.value,
      limit: limit4.value,
    },
  }).then((res) => {
    tableData4.value = res.data;
    if (res.data.length == 0) {
      return;
    }
    total4.value = res.data[0].total;
  });
};
const selectCpyt = () => {
  axios({
    url: "/Material/Select/UseDefinition",
    method: "post",
    data: {
      ytbm: inputytbm.value,
      ytfl: inputytfl.value,
      ytmc: inputytdy.value,
      page: page4.value,
      limit: limit4.value,
    },
  }).then((res) => {
    tableData4.value = res.data;
    total4.value = res.data[0].total;
  });
};
selectCpyt();
const handleSizeChange4 = (val: number) => {
  axios({
    url: "/Material/Select/UseDefinition",
    method: "post",
    data: {
      ytbm: inputytbm.value,
      ytfl: inputytfl.value,
      ytmc: inputytdy.value,
      page: page4.value,
      limit: limit4.value,
    },
  }).then((res) => {
    tableData4.value = res.data;
    total4.value = res.data[0].total;
  });
};
const handleCurrentChange4 = (val: number) => {
  axios({
    url: "/Material/Select/UseDefinition",
    method: "post",
    data: {
      ytbm: inputytbm.value,
      ytfl: inputytfl.value,
      ytmc: inputytdy.value,
      page: page4.value,
      limit: limit4.value,
    },
  }).then((res) => {
    tableData4.value = res.data;
    total4.value = res.data[0].total;
  });
};

const RowClick4 = (row) => {
  form.cpyt = row.ytmc;

  dialogTableVisible4.value = false;
};

// 标准方案
const selectbzfa = () => {
  const userName = Cookies.get("userName");
  axios({
    url: "/select/Material1",
    method: "post",
    data: {
      cpyt: inputAscpyt.value,
      fabh: inputAsfabh.value,
      userName: userName,
      page: page5.value,
      limit: limit5.value,
    },
  }).then((res) => {
    const materialList = res.data;
    tableData5.value = materialList.map((material) => ({
      // 根据 djzt 的值设置状态
      djzt: material.djzt === 0 ? "待审" : "已审核",
      id: material.id,
      fabh: material.fabh,
      djrq: material.djrq,
      cslx: material.cslx,
      cpyt: material.cpyt,
      kh: material.kh,
      cz: material.cz,
      hd: material.hd,
      kd: material.kd,
      csfs: material.csfs,
      dwjs: material.dwjs,
      ywy: material.ywy,
      ywbm: material.ywbm,
      bz: material.bz,
      zdr: material.zdr,
      zdbm: material.zdbm,
      zdsj: material.zdsj,
      shr: material.shr,
      shsj: material.shsj,
      xgr: material.xgr,
      xgbm: material.xgbm,
      ywygh: material.ywygh,
      ywbmgh: material.ywbmgh,
      famc: material.famc,
      bmgh: material.ywbmgh,
    }));
    if (materialList.length == 0) {
      total5.value = 0;
      return;
    }
    total5.value = res.data[0].total;
  });
};
selectbzfa();
const searbzfa = () => {
  axios({
    url: "/select/Material1",
    method: "post",
    data: {
      cpyt: inputAscpyt.value,
      fabh: inputAsfabh.value,
      userName: userName,
      page: page5.value,
      limit: limit5.value,
    },
  }).then((res) => {
    const materialList = res.data;
    tableData5.value = materialList.map((material) => ({
      // 根据 djzt 的值设置状态
      // 根据 djzt 的值设置状态
      djzt: material.djzt === 0 ? "待审" : "已审核",
      id: material.id,
      fabh: material.fabh,
      djrq: material.djrq,
      cslx: material.cslx,
      cpyt: material.cpyt,
      kh: material.kh,
      cz: material.cz,
      hd: material.hd,
      kd: material.kd,
      csfs: material.csfs,
      dwjs: material.dwjs,
      ywy: material.ywy,
      ywbm: material.ywbm,
      bz: material.bz,
      zdr: material.zdr,
      zdbm: material.zdbm,
      zdsj: material.zdsj,
      shr: material.shr,
      shsj: material.shsj,
      xgr: material.xgr,
      xgbm: material.xgbm,
      ywygh: material.ywygh,
      ywbmgh: material.ywbmgh,
      famc: material.famc,
      bmgh: material.ywbmgh,
    }));
    if (materialList.length == 0) {
      total5.value = 0;
      return;
    }
    total5.value = res.data[0].total;
  });
};
const handleSizeChange5 = (val: number) => {
  axios({
    url: "/select/Material1",
    method: "post",
    data: {
      cpyt: inputAscpyt.value,
      fabh: inputAsfabh.value,
      userName: userName,
      page: page5.value,
      limit: limit5.value,
    },
  }).then((res) => {
    // tableData4.value = res.data;
    const materialList = res.data;

    tableData5.value = materialList.map((material) => ({
      // 根据 djzt 的值设置状态
      // 根据 djzt 的值设置状态
      djzt: material.djzt === 0 ? "待审" : "已审核",
      id: material.id,
      fabh: material.fabh,
      djrq: material.djrq,
      cslx: material.cslx,
      cpyt: material.cpyt,
      kh: material.kh,
      cz: material.cz,
      hd: material.hd,
      kd: material.kd,
      csfs: material.csfs,
      dwjs: material.dwjs,
      ywy: material.ywy,
      ywbm: material.ywbm,
      bz: material.bz,
      zdr: material.zdr,
      zdbm: material.zdbm,
      zdsj: material.zdsj,
      shr: material.shr,
      shsj: material.shsj,
      xgr: material.xgr,
      xgbm: material.xgbm,
      ywygh: material.ywygh,
      ywbmgh: material.ywbmgh,
      famc: material.famc,
      bmgh: material.ywbmgh,
    }));
    if (materialList.length == 0) {
      total5.value = 0;
      return;
    }
    total5.value = res.data[0].total;
  });
};
const handleCurrentChange5 = (val: number) => {
  axios({
    url: "/select/Material1",
    method: "post",
    data: {
      cpyt: inputAscpyt.value,
      fabh: inputAsfabh.value,
      userName: userName,
      page: page5.value,
      limit: limit5.value,
    },
  }).then((res) => {
    // tableData4.value = res.data;
    const materialList = res.data;
    tableData5.value = materialList.map((material) => ({
      // 根据 djzt 的值设置状态
      // 根据 djzt 的值设置状态
      djzt: material.djzt === 0 ? "待审" : "已审核",
      id: material.id,
      fabh: material.fabh,
      djrq: material.djrq,
      cslx: material.cslx,
      cpyt: material.cpyt,
      kh: material.kh,
      cz: material.cz,
      hd: material.hd,
      kd: material.kd,
      csfs: material.csfs,
      dwjs: material.dwjs,
      ywy: material.ywy,
      ywbm: material.ywbm,
      bz: material.bz,
      zdr: material.zdr,
      zdbm: material.zdbm,
      zdsj: material.zdsj,
      shr: material.shr,
      shsj: material.shsj,
      xgr: material.xgr,
      xgbm: material.xgbm,
      ywygh: material.ywygh,
      ywbmgh: material.ywbmgh,
      famc: material.famc,
      bmgh: material.ywbmgh,
    }));
    if (materialList.length == 0) {
      total5.value = 0;
      return;
    }
    total5.value = res.data[0].total;
  });
};

const ddslinput = ref(null);
const RowClick5 = (row) => {
  isDdslDisabled.value = false;
  form.bzfabh = row.fabh;
  form.bzfamc = row.famc;
  form.cpyt = row.cpyt;
  form.kh = row.kh;
  form.cz = row.cz;
  form.hd = row.hd;
  form.kd = row.kd;
  form.dwjs = row.dwjs;
  form.bzfa = "(" + row.fabh + ")" + row.famc;
  checkList.value = row.cslx.split(",");
  checkList1.value = row.csfs.split(",");
  dialogTableVisible5.value = false;
  axios({
    url: "/select/MaterialList",
    method: "post",
    data: {
      id: row.id,
    },
  }).then((res) => {
    const materialList = res.data;
    if (materialList == 0) {
      for (let a = 0; a < 21; a++) {
        addRow();
      }
      return;
    }
    const formattedData = materialList.map((material, index) => ({
      wlbm: material.wlbm,
      wlmc: material.wlmc,
      wlgg: material.wlgg,
      jldw: material.jldw,
      bzsl: material.bzsl,
      bzdj: material.bzdj,
      bzje: material.bzje,
      dwjs: material.dwjs,
      csfs: material.csfs,
      selected: false,
    }));
    formDataList.value = formattedData;
    for (let a = 0; a < 21; a++) {
      addRow();
    }
  });
  ddslinput.value.focus();
};
const windowBzfa = () => {
  dialogTableVisible5.value = true;
};
</script>
<style scoped>
/* 悬停 */
/* #f9f9fc, #fef5f0 */
.el-table {
  /* --el-table-row-hover-bg-color: rgba(0, 158, 250, 0.219) !important; */
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}
/* 选中 */
.el-table {
  /* --el-table-row-hover-bg-color: #fef5f0 !important; */
  --el-table-row-hover-bg-color: rgba(254, 245, 240, 0.8) !important;
}

.custom-dialog {
  position: fixed;
  top: 12%;
  left: 50%;
  width: 20%;
  /* 其他样式... */
}

.vertical-line2 {
  width: 100%; /* 让横线的宽度与整个页面宽度一致 */
  height: 2px;
  left: 0;
  background-color: #d3d5d7; /* 横线的颜色，可以根据你的需求修改 */
  position: fixed;
  top: 0; /* 设置横线的垂直位置，可以根据你的布局调整 */
}

.vertical-line3 {
  width: 100%; /* 让横线的宽度与整个页面宽度一致 */
  height: 1px;
  background-color: #d3d5d7; /* 横线的颜色，可以根据你的需求修改 */
  position: fixed;
  top: 4.5%; /* 设置横线的垂直位置，可以根据你的布局调整 */
  left: 0%;
}
.title {
  font-size: 18px;
}
.demo-pagination-block {
  float: right;
}
::v-deep .el-table .cell {
  padding: 0;
}
::v-deep .el-header {
  padding: 0;
}
.my-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.buttonHeard {
  position: absolute;
  top: 0%;
  right: 1%;
}
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.my-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.lab {
  background-color: rgba(247, 247, 247, 0.903);
  /* border-radius: 5px; */
  text-align: center;
  margin-bottom: 0px;
  text-align: right;
}

.labs {
  margin-bottom: 0px;
}
/* 子表 */
.sticky-header {
  position: sticky;
  top: -1px;
  background-color: #ddd;
}

.table-header {
  border: 1px solid #ccc;
  background: rgb(225, 225, 230);
  /* width: 50px; */
  z-index: 99;
}

table tr td {
  /* width: 50px; */
  /* width: 10vh; */
  height: 30px;
}

table {
  border-collapse: collapse;
  border: 1px solid #ccc;
  width: 100%;
}

input {
  border: 1px solid transparent;
}

td {
  border: 1px solid #ccc;
}
#buttonmForm {
  position: absolute;
  bottom: 3px;
}
.vertical-line2 {
  width: 100%; /* 让横线的宽度与整个页面宽度一致 */
  height: 1px;
  background-color: #d3d5d7; /* 横线的颜色，可以根据你的需求修改 */
  position: fixed;
  top: 4.4%; /* 设置横线的垂直位置，可以根据你的布局调整 */
}
.--el-dialog-padding-primary {
  padding: 0;
}
.table-value:hover {
  cursor: pointer;
  z-index: 11;
}
.red-asterisk {
  position: relative;
}
.red-asterisk::before {
  content: "*";
  color: red;
  /* position: absolute;
  left: 5px;
  top: 10px;
  margin-right: 4px; */
}
.dialogDiv {
  position: relative;
  top: 10px;
}
.flex-grow {
  flex-grow: 1;
}
.demo-basic .block:not(:last-child) {
  border-right: 1px solid var(--el-border-color);
}
.demo-basic .block {
  flex: 1;
}
::-webkit-scrollbar {
  width: 5px;
}
</style>
